package com.cloudpan.common.annotate;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Author sc
 * @DATE 2023/11/7 13:25
 * @Description: 校验密码
 * @Version 1.0
 */
public class PWDValidator implements ConstraintValidator<PasswordVaild,String> {

    private static final String REGEX = "^(?![^a-zA-Z]+$)(?!\\D+$).{6,15}$";

    /**
     *
     * @param value
     * @param context
     * @return：返回 true 表示效验通过
     */
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        // 不为null才进行校验
        if (value != null) {
            return value.matches(REGEX);
        }
        return true;
    }

}
